/**
 *
 * @param {Array} data 要转换的 excel 插件导入的数据
 * @param {Object} fieldOptions 列名:字段 对应对象
 */
export function convertExcelData(data, fieldOptions) {
  // 导入表的列名字段对应关系

  const list = data.map(item => {
    const listItem = {}
    for (const key in item) {
      listItem[fieldOptions[key]] = item[key]
    }
    return listItem
  })

  return list
}

/**
 * 验证要导入的用户、设备所在部门是否存在
 * @param {Array} list 要导入的数据列表
 * @param {Array} nowDepartmentList 当前已存在的部门数据
 */
export function checkNoneDepartment(list, nowDepartmentList) {
  // 要导入的部门数组
  let listDepartmentList = []

  // 返回未建立的部门数组
  const noneDepartmentList = []

  listDepartmentList = list.map(item => {
    return item.departname
  })
  // 返回一个去重后的数组
  listDepartmentList = Array.from(new Set(listDepartmentList))

  nowDepartmentList = nowDepartmentList.map(item => {
    return item.departname
  })

  listDepartmentList.forEach(item => {
    if (nowDepartmentList.indexOf(item) === -1) {
      noneDepartmentList.push(item)
    }
  })

  return noneDepartmentList
}
